package assdraw2.canvas.abstraction;

import java.awt.Color;
import java.awt.Polygon;
import java.awt.Rectangle;
import assdraw2.canvas.presentation.Visitor;


public class Triangle extends Shape{

	//super x,y is bottom left corner
	
	//bottom right corner
	private double x2;
	private double y2;
	
	//top corner
	private double x3;
	private double y3;
	
	public Triangle(double x, double y, double width, double height, Color c){
		super(x,y,c);
		
		x2 = x + width;
		y2 = y;
		x3 = x + width/2;
		y3 = y - height;
	}

	public Triangle(double x, double y, Color c){
		super(x,y,c);
		x2 = x + 30;
		y2 = y;
		
		x3 = x + 15;
		y3 = y - 26;		
	}
	
	@Override
	public void scale(double fx, double fy) {
		x2 = getX() + (x2 - getX()) * fx;
		y2 = getY() + (y2 - getY()) * fy;
		x3 = getX() + (x3 - getX()) * fx;
		y3 = getY() + (y3 - getY()) * fy;
	}
	
	@Override
	public boolean contains(double x2, double y2) {
		Polygon p = new Polygon();
		p.addPoint((int)getX(), (int)getY());
		p.addPoint((int)this.x2, (int)this.y2);
		p.addPoint((int)x3, (int)y3);
		return p.contains(x2, y2);
	}


	@Override
	public void accept(Visitor v) {
		v.visit(this);
	}

	@Override
	public Rectangle getBoundary() {
		return new Rectangle((int)getX(), (int)y3, (int)(x2-getX()), (int)(getY()-y3));
	}

	public double getX2() {
		return x2;
	}

	public void setX2(double x2) {
		this.x2 = x2;
	}

	public double getY2() {
		return y2;
	}

	public void setY2(double y2) {
		this.y2 = y2;
	}

	public double getX3() {
		return x3;
	}

	public void setX3(double x3) {
		this.x3 = x3;
	}

	public double getY3() {
		return y3;
	}

	public void setY3(double y3) {
		this.y3 = y3;
	}
	
	@Override
	public void move(double x, double y){
		double deltaX = x - getX();
		double deltaY = y - getY();
		setX(x);
		setY(y);
		x2 += deltaX;
		y2 += deltaY;
		x3 += deltaX;
		y3 += deltaY;
	}
}
